package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import pojo.Orders;
import service.IOrderService;
import service.impl.OrderServiceImpl;
import util.LayData;

import java.util.List;

@Controller
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    private IOrderService orderService = new OrderServiceImpl();

    @PostMapping("/OrderByPid/{pid}")
    @ResponseBody
    public LayData getOrderByPid(@PathVariable(value = "pid") int pid){
        LayData ld = new LayData();

        ld.setCode(0);
        ld.setMsg("");
        ld.setData(orderService.getOrderByPid(pid));

        return ld;
    }

    @PostMapping("/OrderSave")
    @ResponseBody
    public boolean saveOrder(@RequestBody Orders o){
        boolean b = orderService.saveOrder(o);
        return b;
    }

    @PostMapping("/OrderDelete/{oid}")
    @ResponseBody
    public boolean deleteOrder(@PathVariable(value = "oid") int oid){
        return orderService.deleteOrder(oid);
    }
}
